﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using EARS.App_Code;

namespace EARS
{
    public partial class MyEvent1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnUnregister_Click(object sender, EventArgs e)
        {
            btnConfirm.Visible = true;
            btnCancel.Visible = true;
            btnClose.Visible = false;
            lblPopUp.Text = "Are your sure you want to unregister for this event?";
            mpe.Show();
        }

        protected void btnDetails_Click(object sender, EventArgs e)
        {
            Session["EventDetails"] = lblEventName.Text;
            Response.Redirect("~/Protected/EventDetails.aspx");
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            mpe.Hide();
            btnConfirm.Visible = false;
            btnCancel.Visible = false;
            btnClose.Visible = true;
            Participation p = new Participation();
            try
            {
                p.Unregister(lblEventName.Text, HttpContext.Current.User.Identity.Name);
                lblPopUp.Text = "Successfully unregistered!";
                mpe.Show();
            }
            catch (SqlException ex)
            {
                lblPopUp.Text = "Error: Unable to unregister event.";
                mpe.Show();
            }
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            mpe.Hide();
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            mpe.Hide();
        }
    }
}